using MediatR;
using Microsoft.AspNetCore.Mvc;
using WMS.Api.Application.Commands.Records;
using WMS.Common;
using WMS.Domain;

namespace WMS.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RecordController : ControllerBase
    {
        private readonly IMediator _mediator;
        private readonly ILogger<RecordController> _logger;

        public RecordController(IMediator mediator, ILogger<RecordController> logger)
        {
            _mediator = mediator;
            _logger = logger;
        }

        /// <summary>
        /// 分页获取金额变动记录
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>分页数据</returns>
        [HttpGet]
        public async Task<ApiResult<PagedList<Record>>> GetRecordsPaged([FromQuery] GetRecordsPagedQuery query, CancellationToken cancellationToken)
        {
            try
            {
                return await _mediator.Send(query, cancellationToken);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "获取金额变动记录时发生错误");
                return new ApiResult<PagedList<Record>>("获取金额变动记录")
                {
                    isSuc = false,
                    code = StatusCodeEnum.ParamError,
                    msg = $"获取金额变动记录失败：{ex.Message}",
                    data = new PagedList<Record>()
                };
            }
        }
    }
} 